<?php
/**
 * Created by PhpStorm.
 * User: jim
 * Date: 2016-12-28
 * Time: 0:13
 */

namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class Coupon extends Model
{
    protected $table='coupon';

    //查找满足订单金额的优惠券
    public function selectCoupon($threshold)
    {
        $id = session('homeuser');
        $cou = $this->where([['user_id',$id],['threshold','<=',$threshold],['status',1],['end','>',time()]])->orwhere([['user_id',$id],['class','=',2],['status',1],['end','>',time()]])->get();
        if($cou->count() != 0){
            $cou->num = $cou->count();
            return $cou;
        }else{
            return null;
        }
    }
}